package com.njlime.cms.service.sys;

import com.njlime.cms.entities.LiveComment;
import com.njlime.cms.repository.sys.LiveCommentDao;
import com.njlime.core.helper.GlobalValue;
import com.njlime.core.helper.PageBean;
import com.njlime.member.entiies.MemberComment;
import com.njlime.member.service.sys.MemberService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * Created by Dean on 2017/10/13.
 */
@Service
@Transactional(readOnly = true)
public class LiveCommentService {
    @Resource
    private LiveCommentDao liveCommentDao;
    @Resource
    private LiveService liveService;
    @Resource
    private MemberService memberService;

    /**
     * 获取详情
     * @param id
     * @return
     */
    public LiveComment findOne(Integer id){
        return liveCommentDao.findOne(id);
    }

    /**
     * 分页列表
     * @param pageBean
     * @param comment
     * @return
     */
    public PageBean list(PageBean pageBean, LiveComment comment) {
        return liveCommentDao.list(pageBean, comment);
    }

    /**
     * 点赞
     * @param id
     * @return
     */
    @Transactional(readOnly = false)
    public int like(int id ){
        return liveCommentDao.like(id);
    }

    /**
     * 评论置顶取消置顶
     * @param id
     * @return
     */
    @Transactional(readOnly = false)
    public int top(int id ){
        return liveCommentDao.top(id);
    }

    /**
     * 回复
     * @param id
     * @param reply
     * @param userId
     * @return
     */
    @Transactional(readOnly = false)
    public int reply(int id ,String reply,Integer userId){
        return liveCommentDao.reply(id,reply,userId);
    }

    /**
     * 删除
     * @param comment
     * @return
     */
    @Transactional(readOnly = false)
    public int del(LiveComment comment){
        int count =  liveCommentDao.del(comment.getId());
        comment = liveCommentDao.findOne(comment.getId());
        if(comment.getStatus() == GlobalValue.AUDITED){
            liveService.updateCommentNum(comment.getLive_id(),-1);
        }
        return count;
    }

    /**
     * 审核
     * @param comment
     */
    @Transactional(readOnly = false)
    public void auditComment(LiveComment comment, MemberComment memberComment) {
        liveCommentDao.auditComment(comment.getId());
        memberService.saveComment(memberComment);
        liveService.updateCommentNum(comment.getLive_id(), 1);
    }


}
